package wineshop.service.customer;

import static org.junit.Assert.*;

import javax.naming.NamingException;

import org.junit.Test;

import wineshop.domain.market.Customer;
import wineshop.test.CustomerBeanITRemote;

public class CustomerBeanTest extends AbstractEJBTest {

	@Test
	public void shouldCreateANewCustomer() throws NamingException {
		CustomerBeanITRemote customerBean = (CustomerBeanITRemote) context.lookup("wineshop.test.CustomerBeanITRemote");

		Customer customer = new Customer("jack", "robben", "jr55");
		customerBean.createCustomer(customer, "pass".toCharArray());

		Customer result = customerBean.getCustomerByUserName("jr55");
		assertNotNull(result);
		assertEquals("jack", result.getName());
		assertEquals("robben", result.getSurename());
		assertTrue(customerBean.isValidCustomer("jr55", "pass".toCharArray()));
	}

	@Test
	public void shouldNotBeValidWithIncorrectPassword() throws NamingException {
		CustomerBeanITRemote customerBean = (CustomerBeanITRemote) context.lookup("wineshop.test.CustomerBeanITRemote");

		Customer customer = new Customer("jack", "robben", "jr55");
		customerBean.createCustomer(customer, "pass".toCharArray());

		assertTrue(customerBean.isValidCustomer("jr55", "pass".toCharArray()));
		assertFalse(customerBean.isValidCustomer("jr55", "past".toCharArray()));
	}
}
